package com.lh.pro.server;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import com.lh.pro.rpc.UserService;
import com.sise.service.UserRpcService;

import java.io.IOException;

/**
 * 作者：idea
 * 日期：2018/8/11
 * 描述：自定义的一个dubbo服务生产者,不需要依赖于xml的写法
 */
public class MyApplication {
    public static void main(String[] args) throws IOException {
        UserRpcService userRpcService=new UserService();
        ApplicationConfig applicationConfig=new ApplicationConfig();
        applicationConfig.setName("idea-server");

        //注册中心的连接配置
        RegistryConfig registryConfig=new RegistryConfig();
        registryConfig.setAddress("zookeeper://127.0.0.1:2181");

        //服务提供方的协议配置
        ProtocolConfig protocol=new ProtocolConfig();
        protocol.setName("dubbo");
        protocol.setPort(12345);
        protocol.setThreads(200);
        //这是一个比较重类型的对象
        ServiceConfig<UserRpcService> serviceServerConfig=new ServiceConfig<UserRpcService>();
        serviceServerConfig.setApplication(applicationConfig);
        serviceServerConfig.setRegistry(registryConfig);
        serviceServerConfig.setProtocol(protocol);
        serviceServerConfig.setInterface(UserRpcService.class);

        System.out.println("服务已经注册");
        System.in.read();
    }
}
